#!/usr/bin/env python
# -*- coding: utf-8 -*- 
from flask.ext.wtf import Form, TextField, TextAreaField, SubmitField
from models import db, User

class ContactForm(Form):
    """ContactForm"""
    name=TextField("Name")
    email=TextField("Email")
    subject=TextField("Subject")
    message= TextAreaField("Message")
    submit = SubmitField("Send")
    
class HeiyixiaForm(Form):
    """docstring for HeiyixiaForm"""
    heiyixiaContent = TextAreaField("Heishenme")
    username = TextField("Username")
    submit = SubmitField("黑一下")

class SignupForm(Form):
    """docstring for SignupForm"""
    username = TextField("用户名",  [validators.Required("Please enter your first name.")])
    email = TextField("Email",  [validators.Required("Please enter your email address."), validators.Email("Please enter your email address.")])
    password = PasswordField('Password', [validators.Required("Please enter a password.")])
    submit = SubmitField("Create account")
    def __init__(self, *arg, **kwargs):
       Form.__init__(self, *arg, **kwargs)
    def validate(self):
        if not Form.validate(self):
           return False

        user = User.query.filter_by(email = self.email.data.lower()).first()
        if user:
            self.email.errors.append("That email is already taken")
            return False
        else:
            return True 